import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 解决重复点击导航路由报错
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}

export default new Router({
  routes: [
    {  // 默认路由
      path: '/',
      redirect: "/login"
    },
    { // 登录
      path: '/login',
      name: 'login',
      component: ()=>import("../views/login") // 按需加载
    },
    { // 主页
      path: '/index',
      name: 'index',
      component: ()=>import("../views/index"),
      children:[ // 子路由

        { // 帐户管理模块
          path: 'acc',
          name: 'acc',
          component: ()=>import("../views/account/index")
        },
        { // 类型管理模块
          path: 'cate',
          name: 'cate',
          component: ()=>import("../views/cate/index")
        },
        { // 部门管理模块
          path: 'dept',
          name: 'dept',
          component: ()=>import("../views/dept/index")
        },
        { // 学生管理模块
          path: 'stu',
          name: 'stu',
          component: ()=>import("../views/stu/index")
        }
      ]
    },
    { // 布局
      path: '/layout',
      name: 'layout',
      component: ()=>import("../views/layout"), // 按需加载
      children: [
        { // 欢迎页
          path: 'welcome',
          name: 'welcome',
          component: ()=>import("../views/welcome")
        },
        { // 表单
          path: 'userform',
          name: 'userform',
          component: ()=>import("../views/userform") // 按需加载
        },
        { // 表格
          path: 'usertable',
          name: 'usertable',
          component: ()=>import("../views/usertable") // 按需加载
        }
      ]
    }

  ]
})
